import { Entity, Column, PrimaryGeneratedColumn , OneToMany, ManyToOne } from 'typeorm';
import { IsEmail } from 'class-validator';
import { Role } from './role';
import { MemoLists } from './memo_lists';

@Entity()
class User {
    @PrimaryGeneratedColumn()
    id: number;

    @Column({
        type: "varchar",
        length: 80,
        nullable: false,
    })
    name: string;

    @Column({
        type: "varchar",
        length: 100,
        default: ''
    })
    // @IsEmail()
    email: string;

    @Column({
        type: "varchar",
        length: 12,
        nullable: false,
    })
    password: string;

    @Column({
        type: "varchar",
        length: 11,
        default: ''
    })
    phone: string;

    @Column({
        type: "varchar",
        length: 255,
        nullable: true
    })
    token: string;

    @Column({
        type: "varchar",
        length: 255,
        nullable: true
    })
    avater: string;

    @ManyToOne(type => Role, role => role.id)
    role: Role;

    @OneToMany(type => MemoLists,memoLists => memoLists.user)
    memoLists: Array<MemoLists>;
}

export { User };